package com.wyj.wuliwuli.common;

import com.alibaba.fastjson.annotation.JSONType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * @Author wyj
 * @Date 2022.2.14 20:50
 * @Version 1.0
 * @Description
 */
@Data
@JSONType
@NoArgsConstructor
@AllArgsConstructor
public class AjaxResult {

    private int code = HttpStatus.OK.value();
    private String message = "操作成功";
    private Object data;

    public static AjaxResult of() {
        return new AjaxResult();
    }

    /**
     * 返回一个失败的结果
     * @param message
     * @return
     */
    public static AjaxResult fail(String message) {
        AjaxResult ajaxResult = of();
        ajaxResult.setCode(HttpStatus.BAD_REQUEST.value());
        ajaxResult.setMessage(message);
        return ajaxResult;
    }

    /**
     * 返回一个成功的结果
     * @param data
     * @return
     */
    public static AjaxResult ok(Object data) {
        AjaxResult ajaxResult = of();
        ajaxResult.setData(data);
        return ajaxResult;
    }
}
